//
//  BGFaBuViewController.m
//  bigMall
//
//  Created by ios on 16/8/7.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGFaBuViewController.h"
#import "BGFuJiaController.h"
#import "UIView+FrameExtension.h"
#import "BGJieTiJiaGeController.h"
#import "BGDateResult.h"
#import "BGFenLeiModel.h"
#import "BGTwoLevelDataModel.h"
#import "BGGetAddGoodsParamResultModel.h"
#import "BGGetAddGoodsParamResModel.h"
#import "BGGetAddGoodsParamIdAndValueModel.h"
#import "BGCalculateMarginModel.h"
#import "BGCalculateCreditModel.h"
#import "BGCangDanController.h"
#import "BGAddGoodsStepOneModel.h"
#import "BGOwnGoodsDetailModel.h"
#import "BGgetInfoByNamePhoneModel.h"
#import "MBProgressHUD.h"
#import "MBProgressHUD+MJ.h"
#import "LTOVEPickView.h"


@interface BGFaBuViewController ()<UIPickerViewDelegate,UIPickerViewDataSource,UIScrollViewDelegate> {
    
    int zhifukuan;//支付款
    int yue;//余额
    
    NSString *marginStr;//保证金
    NSString *creditStr;//信誉值
    NSString *totalPriceStr;//根据商城还是拍卖来变化的
    NSString *addFrom;//从哪来的啊
    NSString *payScaleStr;//支付的比例
    NSString *priceStr;
    NSString *leastNumberStr;
    NSString *toUserStr;
    //    NSString *cashStr;//金额啊
    
    NSString *starTime;//时间戳
    NSString *stopTime;
    
    NSMutableArray *idArr;
    
    UIView *zhifuView;
    CGFloat zhifuViewY;
    UILabel *lab311;
    UITextField *filed311;
    UITextField *filed312;
    UITextField *filed313;
    
    UITextField *filed221;
    UITextField *filed241;
    UIButton *btn43;
    UIView *dingxiangdan;
    UIView *v2;
    UIScrollView *_scrollView;
    UITextField*filed11;
    UITextField*filed12;
    UITextField*filed13;
    UITextField*filed14;
    UILabel *lab22;
    UITextField *filed22;
    UITextField*filed21;//发布的类型
    UIButton *btn23;
    UIImageView *image23;
    UITextField*filed23;
    UILabel *lab23;
    UILabel *lab24;
    UITextField*filed24;
    UIButton *btn25;
    UIImageView *image25;
    UILabel *lab25;
    UITextField*filed25;
    UITextField *filed31;
    UIButton *btn32;
    UIImageView *image32;
    UITextField*filed32;
    UILabel *lab32;
    UIButton *btn33;
    UIImageView *image33;
    UITextField*filed33;
    UILabel *lab33;
    UITextField*filed41;
    UITextView *filed46;
    UILabel *lab331;
    UILabel *lab332;
    UITextField *filed44;
    UITextField *filed42;
    UITextField *filed45;
    UITextField *filed43;
    UIButton *btn31;
    
    //picker
    UIView *wancheng;
    NSString *place;
    NSMutableArray *oneArr;
    NSMutableArray *twoArr;
    NSMutableArray *threeArr;
    NSMutableArray *oneTitleArr;
    NSMutableArray *twoTitleArr;
    NSMutableArray *threeTitleArr;
    NSString *str1;
    NSString *str2;
    NSString *str3;
    UIDatePicker *_dataPicker;
    NSString *_dateStr;
    
    NSMutableArray *oneAreaId;//地址的Id
    NSMutableArray *twoAreaId;
    NSMutableArray *threeAreaId;
    NSString *areaIdStr1;
    NSString *areaIdStr2;
    NSString *areaIdStr3;
    
    //picker1
    UIPickerView *picker1;
    NSMutableArray *fenleiOneTitleArr;
    NSMutableArray *fenleiTwoTitleArr;
    NSMutableArray *fenleiThreeTitleArr;
    
    //picker2
    UIPickerView *picker2;
    NSArray *picker2Arr;
    NSString *picker2Str;
    NSInteger picker2Index;
    NSString *pickerId;//属性的Id
    NSArray *arrId;//保存属性的Id
    
    //标记是哪个日期
    NSInteger dateIndex;
    
    //发布商品的信息
    NSMutableArray *addTo;
    NSMutableArray *isPorted;
    NSMutableArray *payType;
    NSMutableArray *publishType;
    NSMutableArray *deliveryType;
    NSMutableArray *payMethod;
    
    NSMutableArray *addToid;
    NSMutableArray *isPortedid;
    NSMutableArray *payTypeid;
    NSMutableArray *publishTypeid;
    NSMutableArray *deliveryTypeid;
    NSMutableArray *payMethodid;
    
    NSString *addtoStr;
    NSString *isPortedStr;
    NSString *payTypeidStr;
    NSString *publishTypeidStr;
    NSString *deliveryTypeidStr;
    
    CGFloat v2Y;
    
    NSString *cashStr;//可使用金额
    
    NSString *yikoujia;//一口价
    
    NSString *goods_id;//返回的商品id
    
    UIBarButtonItem *back;//返回按钮
    
}
@property (nonatomic,strong) UIPickerView *picker;
@end

@implementation BGFaBuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"发布商品";
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStylePlain target:self action:@selector(next)];
    self.navigationItem.rightBarButtonItem = right;
    
    back = [[UIBarButtonItem alloc] init];
    back.title = @"上一步";
    
    self.navigationItem.backBarButtonItem = back;
    //     [self.navigationItem.backBarButtonItem addObserver:self forKeyPath:@"back" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionPrior  context:nil];
    
    [self createUI];
    [self initDat];
    [self loadPlist];
    [self createPicker];
    [self createDataPicker];
    [self fabuParam];
    //    [self panduanEdit];//判断是否能编辑
    //    self.edgesForExtendedLayout = UIRectEdgeNone;
    
}
//- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
//
//    if ([keyPath isEqualToString:@"back"]) {
//        self.type = @"back";
//    }
//
//}
//- (void)dealloc {
//    [self.navigationItem.backBarButtonItem removeObserver:self forKeyPath:@"back" context:nil];
//}
- (void)clean {
    
    filed11.text = @"";
    filed12.text = @"";
    filed13.text = @"";
    filed14.text = @"";
    
    filed22.text = @"";
    filed221.text = @"";
    filed24.text = @"";
    filed241.text = @"";
    filed25.text = @"";
    
    filed31.text = @"";
    filed311.text = @"";
    filed312.text = @"";
    filed313.text = @"";
    filed33.text = @"";
    
    filed41.text = @"";
    filed42.text = @"";
    filed43.text = @"";
    filed44.text = @"";
    filed45.text = @"";
    
}
- (void)panduanEdit {
    
    for (UIView *btn in _scrollView.subviews) {
        btn.userInteractionEnabled = NO;
    }
    
}
//发布的各种属性
- (void)fabuParam {
    
    [BGDateResult getAddGoodsParamSuccess:^(NSObject *result) {
        
        BGGetAddGoodsParamResultModel *model = (BGGetAddGoodsParamResultModel *)result;
        
        BGGetAddGoodsParamResModel *Model = model.res;
        
        //
        NSArray *addto = [NSArray arrayWithArray:Model.addTo];
        addTo = [NSMutableArray array];
        addToid = [NSMutableArray array];
        
        for (BGGetAddGoodsParamIdAndValueModel *model in addto) {
            
            [addTo addObject:model.value];
            [addToid addObject:model.ids];
            
        }
        //        NSLog(@"add%@",addTo);
        //
        NSArray *isPorteda = [NSArray arrayWithArray:Model.isPorted];
        isPorted = [NSMutableArray array];
        isPortedid = [NSMutableArray array];
        
        for (BGGetAddGoodsParamIdAndValueModel *model in isPorteda) {
            
            [isPorted addObject:model.value];
            [isPortedid addObject:model.ids];
            
        }
        //        NSLog(@"isp%@",isPorted);
        //
        NSArray *payTypea = [NSArray arrayWithArray:Model.payType];
        payType = [NSMutableArray array];
        payTypeid = [NSMutableArray array];
        
        for (BGGetAddGoodsParamIdAndValueModel *model in payTypea) {
            
            [payType addObject:model.value];
            [payTypeid addObject:model.ids];
            
        }
        //
        NSArray *publishTypea = [NSArray arrayWithArray:Model.publishType];
        publishType = [NSMutableArray array];
        publishTypeid = [NSMutableArray array];
        
        for (BGGetAddGoodsParamIdAndValueModel *model in publishTypea) {
            
            [publishType addObject:model.value];
            [publishTypeid addObject:model.ids];
            
        }
        //        NSLog(@"pub%@",publishType);
        //
        NSArray *deliveryTypea = [NSArray arrayWithArray:Model.deliveryType];
        deliveryType = [NSMutableArray array];
        deliveryTypeid = [NSMutableArray array];
        
        for (BGGetAddGoodsParamIdAndValueModel *model in deliveryTypea) {
            
            [deliveryType addObject:model.value];
            [deliveryTypeid addObject:model.ids];
            
        }
        //暂时不需要
        NSArray *payMethoda = [NSArray arrayWithArray:Model.payMethod];
        payMethod = [NSMutableArray array];
        payMethodid = [NSMutableArray array];
        
        for (BGGetAddGoodsParamIdAndValueModel *model in payMethoda) {
            
            [payMethod addObject:model.value];
            [payMethodid addObject:model.ids];
            
        }
        
        [picker2 reloadAllComponents];
        [picker2 reloadInputViews];
        
    } failure:^(NSError *error) {
        
    }];
    
}
- (void)createDataPicker {
    
    _dataPicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bottom - BGHight / 3, BGWidth, BGHight / 3)];
    _dataPicker.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_dataPicker];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    _dataPicker.locale = locale;
    _dataPicker.hidden = YES;
    //NSTimeInterval oneYearTime = 365 * 24 * 60 * 60;
    //NSDate *todayDate = [NSDate date];
    //NSDate *oneYearFromToday = [todayDate dateByAddingTimeInterval:oneYearTime];
    //NSDate *twoYearsFromToday = [todayDate dateByAddingTimeInterval:2 * oneYearTime];
    //_dataPicker.minimumDate = oneYearFromToday;
    //_dataPicker.maximumDate = twoYearsFromToday;
    _dataPicker.datePickerMode = UIDatePickerModeDate;
    [_dataPicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
                                                                                                 
}
- (void)datexianshi {
    
    dateIndex = 1;
    if (dateIndex == 1) {
        
        
        NSDate *date = [NSDate date];
        
        NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:3600*8];
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        [formatter setTimeZone:timeZone];
        [formatter setDateFormat:@"YYYY年MM月dd日"];
        //    [formatter setDateFormat:@"yyyy年MM月dd日(EEEE) HH:mm:ss"];
        _dateStr = [formatter stringFromDate:date];
        NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]];
        NSString *times = [timeSp substringToIndex:10];
        filed44.text = _dateStr;
        starTime = times;
        
    }
    _dataPicker.hidden = NO;
    wancheng.hidden = NO;
    
    
}
- (void)dateChanged:(id)sender {
    
    UIDatePicker *datePicker = sender;
    
    NSDate *date = [datePicker date];
    
    NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:3600*8];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"YYYY年MM月dd日"];
    //    [formatter setDateFormat:@"yyyy年MM月dd日(EEEE) HH:mm:ss"];
    _dateStr = [formatter stringFromDate:date];
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]];
    NSString *times = [timeSp substringToIndex:10];
    
    if (dateIndex == 1) {
        
        filed44.text = _dateStr;
        starTime = times;
        
    }else if (dateIndex == 0) {
        
        filed45.text = _dateStr;
        stopTime = times;
        
    }
    
    
}
- (void)createPicker {
    
    //picker
    self.picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view.bottom - BGHight / 3, BGWidth, BGHight / 3)];
    
    self.picker.delegate = self;
    self.picker.dataSource = self;
    self.picker.backgroundColor = [UIColor whiteColor];
    self.picker.hidden = YES;
    self.picker.tag = 1;
    [self.picker selectRow:0 inComponent:0 animated:YES];
    [self.view addSubview:self.picker];
    [self.picker showsSelectionIndicator];
    [self.picker reloadAllComponents];
    
    //picker1
    picker1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view.bottom - BGHight / 3, BGWidth, BGHight / 3)];
    picker1.delegate = self;
    picker1.dataSource = self;
    picker1.backgroundColor = [UIColor whiteColor];
    picker1.hidden = YES;
    picker1.tag = 2;
    [self.view addSubview:picker1];
    
    //picker2
    picker2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view.bottom - BGHight / 3, BGWidth, BGHight / 3)];
    picker2.delegate = self;
    picker2.dataSource = self;
    picker2.backgroundColor = [UIColor whiteColor];
    picker2.hidden = YES;
    picker2.tag = 3;
    [self.view addSubview:picker2];
    
    //创建确定的按钮
    wancheng = [[UIView alloc] initWithFrame:CGRectMake(0, self.picker.y - 30, BGWidth, 30)];
    wancheng.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:wancheng];
    
    UIView *a = [[UIView alloc] initWithFrame:CGRectMake(0, 29, BGWidth, 1)];
    a.backgroundColor = [UIColor lightGrayColor];
    [wancheng addSubview:a];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(wancheng.width - BGWidth / 4.3, 0, BGWidth / 4.3, 30)];
    [btn setTitle:@"完成" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    btn .titleLabel.textAlignment = NSTextAlignmentRight;
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    wancheng.hidden = YES;
    [wancheng addSubview:btn];
    
}
- (void)xianshi {
    
    self.picker.hidden = NO;
    wancheng.hidden = NO;
    
}
- (void)xianshiPicker2 {
    
    
    picker2.hidden = NO;
    wancheng.hidden = NO;
    
}
- (void)btnClick {
    
    _dataPicker.date = [NSDate date];
    self.picker.hidden = YES;
    wancheng.hidden = YES;
    _dataPicker.hidden = YES;
    picker1.hidden = YES;
    picker2.hidden = YES;
    
}
- (void)loadPlist {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"area" ofType:@".plist"];
    
    NSArray *mainArr = [NSArray arrayWithContentsOfFile:path];
    
    oneArr = mainArr[0];
    oneAreaId = [NSMutableArray new];
    
    for (NSDictionary *dic in oneArr) {
        
        [oneTitleArr addObject:dic[@"name"]];
        [oneAreaId addObject:dic[@"id"]];
        
    }
    
}

- (void)initDat {
    
    toUserStr = [NSString string];
    leastNumberStr = [NSString string];
    priceStr =[NSString string];
    payScaleStr = [NSString string];
    addFrom = [NSString string];
    totalPriceStr = [NSString string];
    _stepStr = [NSString string];
    areaIdStr1 = [NSString new];
    areaIdStr2 = [NSString new];
    areaIdStr3 = [NSString new];
    stopTime = [NSString string];
    starTime = [NSString string];
    addtoStr = [NSString string];
    isPortedStr = [NSString string];
    publishTypeidStr = [NSString string];
    payTypeidStr = [NSString string];
    deliveryTypeidStr = [NSString string];
    marginStr = [NSString string];
    creditStr = [NSString string];
    twoArr = [NSMutableArray array];
    threeArr = [NSMutableArray array];
    oneTitleArr = [NSMutableArray array];
    twoTitleArr = [NSMutableArray array];
    threeTitleArr = [NSMutableArray array];
    
}
- (void)panduanguadanfangshi {
    
    if ([filed32.text isEqualToString:@"保证金挂单"]) {
        
        publishTypeidStr= @"1";
        btn33.hidden = YES;
        image33.hidden = YES;
        btn33.hidden = YES;
        lab33.text = @"保证金 :";
        lab331.hidden = NO;
        lab331.text = [NSString stringWithFormat:@"当前可用金额：%d",0];
        
        lab332.hidden = NO;
        lab332.text = [NSString stringWithFormat:@"挂单需要冻结金额：%d",0];
        
        filed33.hidden = YES;
        
        NSMutableAttributedString *str331 = [[NSMutableAttributedString alloc] initWithString:lab331.text];
        [str331 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(7, str331.length - 7)];
        lab331.attributedText = str331;
        
        NSMutableAttributedString *str332 = [[NSMutableAttributedString alloc] initWithString:lab332.text];
        [str332 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(9, str332.length - 9)];
        lab332.attributedText = str332;
        creditStr = @"0.000";
        self.storePicStra = @"";
        
    }else if ([filed32.text isEqualToString:@"信誉挂单"]) {
        
        publishTypeidStr= @"2";
        btn33.hidden = YES;
        image33.hidden = YES;
        btn33.hidden = YES;
        lab33.text = @"信誉值 :";
        lab331.hidden = NO;
        lab331.text = [NSString stringWithFormat:@"当前信誉值：%d",0];
        lab332.hidden = NO;
        lab332.text = [NSString stringWithFormat:@"挂单使用信誉值：%d",0];
        filed33.hidden = YES;
        
        NSMutableAttributedString *str331 = [[NSMutableAttributedString alloc] initWithString:lab331.text];
        [str331 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6, str331.length - 6)];
        lab331.attributedText = str331;
        
        NSMutableAttributedString *str332 = [[NSMutableAttributedString alloc] initWithString:lab332.text];
        [str332 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(8, str332.length - 8)];
        lab332.attributedText = str332;
        
        marginStr = @"0.00";
        self.storePicStra = @"";
        
    }else {
        
        publishTypeidStr= @"0";
        btn33.hidden = NO;
        image33.hidden = NO;
        lab331.hidden = YES;
        lab332.hidden = YES;
        filed33.hidden = NO;
        lab33.text = @"仓单图片 :";
        marginStr = @"0.00";
        creditStr = @"0.000";
        
        if (self.storePicStra == nil ) {
            self.storePicStra = @"";
        }
        
    }
    
    [self valuechange];
    
}
- (void)panduanfabuleixing1 {
    
    if ([filed21.text isEqualToString:@"拍卖"]) {
        filed23.text = @"";
    }
    
}
- (void)panduanfabuleixing {
    
    if ([filed21.text isEqualToString:@"拍卖"]) {
        
        toUserStr = @"0";
        leastNumberStr = filed14.text;
        priceStr = @"0";
        payTypeidStr = @"1";
        isPortedStr = @"0";
        addFrom = @"1";
        addtoStr = @"1";
        
        btn31.hidden = YES;
        filed41.userInteractionEnabled = NO;
        filed41.placeholder = @"";
        
        //        filed23.text = @"";
        
        filed23.hidden = NO;
        
        filed24.hidden = YES;
        filed241.hidden = NO;
        filed22.hidden = YES;
        filed221.hidden = NO;
        
        filed25.hidden = NO;
        lab23.hidden = NO;
        lab24.hidden = NO;
        lab25.hidden = NO;
        
        dingxiangdan.y = v2Y;
        
        //        lab22.hidden = YES;
        //        filed22.hidden = YES;
        //        lab23.hidden = YES;
        //        filed23.hidden = YES;
        btn23.hidden = YES;
        image23.hidden = YES;
        //        lab24.hidden = YES;
        //        filed24.hidden = YES;
        btn25.hidden = YES;
        image25.hidden = YES;
        //        lab25.hidden = YES;
        //        filed25.hidden = YES;
        
        lab22.text = @"起拍价(元):";
        lab22.font = [UIFont systemFontOfSize:14];
        CGSize size22 = [lab22.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab22.font,NSFontAttributeName, nil]];
        lab22.height = size22.height;
        lab22.width = size22.width;
        filed22.textColor = [UIColor redColor];
        
        lab23.text = @"竞拍保证金(%):";
        lab23.font = [UIFont systemFontOfSize:14];
        CGSize size23 = [lab23.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab23.font,NSFontAttributeName, nil]];
        lab23.height = size23.height;
        lab23.width = size23.width;
        filed23.textColor = [UIColor redColor];
        //        filed23.text = @"";
        filed23.userInteractionEnabled = YES;
        
        lab24.text = @"最低加价幅度(元):";
        lab24.font = [UIFont systemFontOfSize:14];
        CGSize size24 = [lab24.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab24.font,NSFontAttributeName, nil]];
        lab24.height = size24.height;
        lab24.width = size24.width;
        filed24.userInteractionEnabled = YES;
        filed24.textColor = [UIColor redColor];
        
        lab25.text = @"一口价(元):";
        lab25.font = [UIFont systemFontOfSize:14];
        CGSize size25 = [lab25.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab25.font,NSFontAttributeName, nil]];
        lab25.width = size25.width;
        lab25.height = size25.height;
        filed25.textColor = [UIColor redColor];
        filed25.x = lab25.right + 10;
        
        filed25.userInteractionEnabled = YES;
        
        filed41.userInteractionEnabled = NO;
        filed41.placeholder = @"不可填";
        
        filed241.placeholder = @"请填写";
        filed25.placeholder = @"请选择";
        
        filed31.placeholder = @"不可选";
        filed31.text = @"全款";
        btn31.hidden = YES;
        
        totalPriceStr = filed221.text;
        
        yikoujia = filed25.text;
        
        [self.view setNeedsDisplay];
        
    }else if ([filed21.text isEqualToString:@"商城"]) {
        
        addtoStr = @"0";
        toUserStr = @"0";
        leastNumberStr = filed24.text;
        priceStr = filed22.text;
        addFrom = @"0";
        filed23.text = @"否";
        filed41.text = @"0";
        
        filed41.userInteractionEnabled = NO;
        filed41.placeholder = @"";
        filed31.placeholder = @"请选择";
        
        dingxiangdan.y = v2Y;
        
        btn31.hidden = NO;
        lab22.hidden = NO;
        filed22.hidden = NO;
        filed221.hidden = YES;
        lab23.hidden = NO;
        filed23.hidden = NO;
        btn23.hidden = NO;
        image23.hidden = NO;
        lab24.hidden = NO;
        filed24.hidden = NO;
        filed241.hidden = YES;
        btn25.hidden = NO;
        image25.hidden = NO;
        lab25.hidden = NO;
        filed25.hidden = NO;
        
        lab22.text = @"单价(元) :";
        lab22.font = [UIFont systemFontOfSize:14];
        CGSize size22 = [lab22.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab22.font,NSFontAttributeName, nil]];
        lab22.height = size22.height;
        lab22.width = size22.width;
        filed22.textColor = [UIColor redColor];
        
        lab23.text = @"是否拆分出售 :";
        lab23.font = [UIFont systemFontOfSize:14];
        CGSize size23 = [lab23.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab23.font,NSFontAttributeName, nil]];
        lab23.height = size23.height;
        lab23.width = size23.width;
        filed23.userInteractionEnabled = NO;
        filed23.textColor = [UIColor blackColor];
        
        lab24.text = @"最小供应量(吨) :";
        lab24.font = [UIFont systemFontOfSize:14];
        CGSize size24 = [lab24.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab24.font,NSFontAttributeName, nil]];
        lab24.height = size24.height;
        lab24.width = size24.width;
        filed24.textColor = [UIColor blackColor];
        
        lab25.text = @"阶梯价格(选填) :";
        lab25.font = [UIFont systemFontOfSize:14];
        CGSize size25 = [lab25.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab25.font,NSFontAttributeName, nil]];
        lab25.width = size25.width;
        lab25.height = size25.height;
        filed25.x = lab25.right + 10;
        filed25.placeholder = @"请选择";
        filed25.textColor = [UIColor blackColor];
        filed25.userInteractionEnabled = NO;
        filed41.userInteractionEnabled = NO;
        filed41.placeholder = @"不可填";
        [self.view setNeedsDisplay];
        totalPriceStr = [NSString stringWithFormat:@"%d",[filed14.text intValue] * [filed22.text intValue]];
        filed241.text = @"0";
        
    }else {
        
        addtoStr = @"2";
        leastNumberStr = filed14.text;
        payTypeidStr = @"3";
        isPortedStr = @"0";
        priceStr = filed22.text;
        filed31.text = @"全款";
        btn31.hidden = YES;
        addFrom = @"0";
        lab22.text = @"单价(元) :";
        lab22.font = [UIFont systemFontOfSize:14];
        CGSize size22 = [lab22.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab22.font,NSFontAttributeName, nil]];
        lab22.height = size22.height;
        lab22.width = size22.width;
        
        filed31.placeholder = @"请选择";
        filed31.text = @"货到付款";
        filed22.hidden = NO;
        filed41.userInteractionEnabled = YES;
        filed41.placeholder = @"请输入";
        btn25.hidden = YES;
        image25.hidden = YES;
        btn23.hidden = YES;
        filed221.hidden = YES;
        image23.hidden = YES;
        filed23.hidden = YES;
        filed24.hidden = YES;
        filed241.hidden = YES;
        filed25.hidden = YES;
        lab23.hidden = YES;
        lab24.hidden = YES;
        lab25.hidden = YES;
        dingxiangdan.y = v2Y - 123;
        filed41.userInteractionEnabled = YES;
        filed41.placeholder = @"请填写";
        totalPriceStr = [NSString stringWithFormat:@"%d",[filed14.text intValue] * [filed22.text intValue]];
        filed311.text = @"0";
        filed312.text = @"0";
        filed313.text = @"100";
        
        //核对用户的信息
        if (![filed41.text isEqualToString:@""] && filed41.text) {
            [self checkToUserInfo];
        }
        
    }
    
    [self panduanzhifufangshi];
    [self valuechange];
    
    
}
+ (BGFaBuViewController *)share {
    
    static BGFaBuViewController *a = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate,^{
        a = [[BGFaBuViewController alloc] init];
    });
    return a;
}
- (void)checkToUserInfo {
    NSLog(@"filed41.text === %@",filed41.text);
    //英文字条件
    NSRegularExpression *tLetterRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[A-Za-z]" options:NSRegularExpressionCaseInsensitive error:nil];
    
    //符合英文字条件的有几个字节
    NSUInteger tLetterMatchCount = [tLetterRegularExpression numberOfMatchesInString:filed41.text options:NSMatchingReportProgress range:NSMakeRange(0, filed41.text.length)];
    NSString *name;
    NSString  *phone;
    if (tLetterMatchCount != 0) {
        name = filed41.text;
        phone= @"";
    } else {
        name = @"";
        phone= filed41.text;
    }
    
    [BGDateResult getgetInfoByName:name pnone:phone success:^(NSObject *result) {
        BGgetInfoByNamePhoneModel *model = (BGgetInfoByNamePhoneModel *)result;
        if ([model.status isEqualToString:@"1"]) {
            NSDictionary *dic = model.res;
            toUserStr = dic[@"user_id"];
        }else {
            NSLog(@"model.msg === %@",model.msg);
            [self showMessage:model.msg];
        }
    } failure:^(NSObject *error) {
        
    }];
}
- (void)next {
    
    [self panduanfabuleixing];
    [self panduanguadanfangshi];
    [self panduanzhifufangshi];
    [self panduanChaifen];
    
    if (filed23.text < 0) {
        [self showMessage:@"竞拍保证金(%)，必须大于0"];
    }
    
    if ([self.type isEqualToString:@"fujia"]) {
        
        BGFuJiaController *a = [[BGFuJiaController alloc] init];
        a.typeId = self.Id;
        a.fabuName = addtoStr;
        a.goods_id = self.goodsId;
        a.inventory = filed14.text;
        
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:a animated:YES];
        
        
    }
    else if ([self.type isEqualToString:@"WFB"]) {
        
        BGFuJiaController *a = [[BGFuJiaController alloc] init];
        self.Id = self.catId;
        a.typeId = self.Id;
        [self panduanfabuleixing];
        a.fabuName = addtoStr;
        a.goods_id = self.goodsId;
        a.status = self.status;
        a.inventory = filed14.text;
        NSLog(@"self.status === %@",self.status);
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:a animated:YES];
        
    }
    else {
        
        //判断仓单的
        if ([filed32.text isEqualToString:@"仓单挂单"]) {
            if (!self.storePicStra || [self.storePicStra isEqualToString:@""]) {
                [self showMessage:@"没选择仓单图片!"];
                return;
            }
        }
        
        //调取到附加信息的提交网络接口
        if ([filed32.text isEqualToString:@"保证金挂单"] ) {
            
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"支付密码" message:[NSString stringWithFormat:@"支付款：%@ 余额：%@",marginStr,cashStr] preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                //检验支付的密码
                [self payPWD:alertController.textFields.firstObject.text];
                
            }];
            [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
                
                textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
                textField.secureTextEntry = YES;
                
            }];
            
            [alertController addAction:cancelAction];
            [alertController addAction:okAction];
            [self presentViewController:alertController animated:YES completion:nil];
            
        }else {
            
            [self panduanguadanfangshi];
            
            [BGDateResult addGoodsStepOneWithPrameDic:
             @{@"catId":[NSString stringWithFormat:@"%@",self.Id],
               @"title":filed12.text,
               @"productCode":filed13.text,
               @"number":filed14.text,
               @"addFrom":addFrom,
               @"addTo":addtoStr,
               @"price":priceStr,
               @"totalPrice":totalPriceStr,
               @"sellMargin":marginStr,
               @"buyMargin":filed23.text,
               //           @"creditNum":creditStr,
               @"isPorted":isPortedStr,
               @"leastNumber":leastNumberStr,
               @"leastAdd":filed241.text,
               @"fixedPrice":yikoujia,
               @"stepPrice":_stepStr,
               @"payType":payTypeidStr,
               @"payScale":[NSString stringWithFormat:@"%@,%@,%@",filed311.text,filed312.text,filed313.text],
               @"publishType":publishTypeidStr,
               @"storePic":self.storePicStra,
               @"toUser":toUserStr,
               @"deliveryArea":filed42.text,
               @"province":areaIdStr1,
               @"city":areaIdStr2,
               @"county":areaIdStr3,
               @"deliveryType":deliveryTypeidStr,
               @"startTime":starTime,
               @"endTime":stopTime,
               @"remark":filed46.text,
               @"payPassword":@"123456",
               @"credit":creditStr
               } success:^(NSObject *result) {
                   
                   BGAddGoodsStepOneModel *model = (BGAddGoodsStepOneModel *)result;
                   
                   if ([model.status isEqualToString:@"1"]) {
                       
                       BGFuJiaController *a = [[BGFuJiaController alloc] init];
                       a.typeId = self.Id;
                       a.fabuName = addtoStr;
                       a.goods_id = model.goods_id;
                       a.inventory = filed14.text;
                       
                       self.goodsId = model.goods_id;
                       
                       self.hidesBottomBarWhenPushed = YES;
                       [self.navigationController pushViewController:a animated:YES];
                       [self showMessage:model.msg];
                       
                   } else {
                       
                       [self showMessage:model.msg];
                       
                   }
                   
                   
                   
               } failure:^(NSError *error) {
                   
               }];
            
        }
        NSLog(@"stopTime%@",stopTime);
        NSLog(@"startTime%@",starTime);
    }
    
}
//网络密码请求成功后 在进行页面信息的核对 然后再跳转
- (void)payPWD:(NSString *)pwd {
    NSLog(@"%@",filed241);
    NSLog(@"stop:%@",stopTime);
    NSLog(@"start%@",starTime);
    [BGDateResult checkPayPasswordCashCreditWithPayPassWord:pwd cash:marginStr credit:creditStr success:^(NSObject *result) {
        
        BGBasicResult *model = (BGBasicResult *)result;
        
        if ([model.status isEqualToString:@"1"]) {
            
            [self panduanguadanfangshi];
            
            [BGDateResult addGoodsStepOneWithPrameDic:
             @{@"catId":[NSString stringWithFormat:@"%@",self.Id],
               @"title":filed12.text,
               @"productCode":filed13.text,
               @"number":filed14.text,
               @"addFrom":addFrom,
               @"addTo":addtoStr,
               @"price":priceStr,
               @"totalPrice":totalPriceStr,
               @"sellMargin":marginStr,
               @"buyMargin":filed23.text,
               //           @"creditNum":creditStr,
               @"isPorted":isPortedStr,
               @"leastNumber":leastNumberStr,
               @"leastAdd":filed241.text,
               @"fixedPrice":filed25.text,
               @"stepPrice":_stepStr,
               @"payType":payTypeidStr,
               @"payScale":[NSString stringWithFormat:@"%@,%@,%@",filed311.text,filed312.text,filed313.text],
               @"publishType":publishTypeidStr,
               @"storePic":self.storePicStra,
               @"toUser":toUserStr,
               @"deliveryArea":filed42.text,
               @"province":areaIdStr1,
               @"city":areaIdStr2,
               @"county":areaIdStr3,
               @"deliveryType":deliveryTypeidStr,
               @"startTime":starTime,
               @"endTime":stopTime,
               @"remark":filed46.text,
               @"payPassword":@"123456",
               @"credit":creditStr
               } success:^(NSObject *result) {
                   
                   BGAddGoodsStepOneModel *model = (BGAddGoodsStepOneModel *)result;
                   
                   if ([model.status isEqualToString:@"1"]) {
                       
                       BGFuJiaController *a = [[BGFuJiaController alloc] init];
                       a.typeId = self.Id;
                       a.fabuName = addtoStr;
                       a.goods_id = model.goods_id;
                       a.inventory = filed14.text;
                       
                       self.goodsId = model.goods_id;
                       
                       self.hidesBottomBarWhenPushed = YES;
                       [self.navigationController pushViewController:a animated:YES];
                       [self showMessage:model.msg];
                       
                   } else {
                       
                       [self showMessage:model.msg];
                       
                   }
                   
                   
                   
               } failure:^(NSError *error) {
                   
               }];
            
        } else {
            
            [self showMessage:model.msg];
            
        }
        
    } failure:^(NSError *error) {
        
    }];
    
}
- (void)showMessage:(NSString *)message {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    
    [alertController addAction:okAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
}
-(void)keyboardHide:(UITapGestureRecognizer*)tap{
    
    [filed12 resignFirstResponder];
    [filed13 resignFirstResponder];
    [filed14 resignFirstResponder];
    [filed22 resignFirstResponder];
    [filed24 resignFirstResponder];
    [filed23 resignFirstResponder];
    [filed25 resignFirstResponder];
    [filed41 resignFirstResponder];
    [filed46 resignFirstResponder];
    [filed311 resignFirstResponder];
    [filed312 resignFirstResponder];
    [filed313 resignFirstResponder];
    
}
//计算保证金和信誉值
- (void)valuechange {
    
    NSInteger num;
    
    if ([filed21.text isEqualToString:@"商城"]) {
        num = [filed14.text integerValue] * [filed22.text integerValue];
    } else if ([filed21.text isEqualToString:@"拍卖"]){
        num = [filed221.text integerValue];
    } else {
        num = [filed14.text integerValue] * [filed22.text integerValue];
    }
    
    
    NSString *type;
    
    if ([filed21.text isEqualToString:@"商城"]) {
        type = @"goods";
    }else if ([filed21.text isEqualToString:@"拍卖"]) {
        type = @"auction";
    }else {
        type = @"goods";
    };
    
    if ([filed32.text isEqualToString:@"保证金挂单"]) {
        
        [BGDateResult calculateMarginWithRole:@"seller" type:type money:[NSString stringWithFormat:@"%ld",(long)num] objId:@"" success:^(NSObject *result) {
            
            BGCalculateMarginModel *model = [[BGCalculateMarginModel alloc] init];
            model = (BGCalculateMarginModel *)result;
            if ([model.status isEqualToString:@"1"]) {
                lab331.text = [NSString stringWithFormat:@"当前可用金额：%@",model.cash];
                lab332.text = [NSString stringWithFormat:@"挂单需要冻结金额：%@",model.margin];
                //                marginStr = model.margin;
                //保证金
                cashStr = model.cash;
                marginStr = model.margin;
                creditStr = @"0.000";
                
                NSMutableAttributedString *str331 = [[NSMutableAttributedString alloc] initWithString:lab331.text];
                [str331 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(7, str331.length - 7)];
                lab331.attributedText = str331;
                
                NSMutableAttributedString *str332 = [[NSMutableAttributedString alloc] initWithString:lab332.text];
                [str332 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(9, str332.length - 9)];
                lab332.attributedText = str332;
                
            } else {
                
                //                [self showMessage:model.msg];
                
            }
            
            
        } failure:^(NSError *error) {
            
        }];
    }else if ([filed32.text isEqualToString:@"信誉挂单"]) {
        
        [BGDateResult CalculateCreditWithRole:@"seller" type:type money:[NSString stringWithFormat:@"%ld",(long)num] success:^(NSObject *result) {
            
            BGCalculateCreditModel *model = [[BGCalculateCreditModel alloc] init];
            model = (BGCalculateCreditModel *)result;
            if ([model.status isEqualToString:@"1"]) {
                lab331.text = [NSString stringWithFormat:@"当前信誉值：%@",model.ownCredit];
                lab332.text = [NSString stringWithFormat:@"挂单使用信誉值：%@",model.credit];
                //信誉值
                creditStr = [NSString stringWithFormat:@"%.3f",model.credit.floatValue];
                marginStr = @"0.000";
                
                NSMutableAttributedString *str331 = [[NSMutableAttributedString alloc] initWithString:lab331.text];
                [str331 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6, str331.length - 6)];
                lab331.attributedText = str331;
                
                NSMutableAttributedString *str332 = [[NSMutableAttributedString alloc] initWithString:lab332.text];
                [str332 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(8, str332.length - 8)];
                lab332.attributedText = str332;
                
            }else {
                
                //                [self showMessage:model.msg];
                
            }
            
            
        } failure:^(NSError *error) {
            
        }];
    }
    
}
- (void)texfiledchange:(UITextField *)filed {
    
    [self panduanfabuleixing];
    
}
- (void)createUI {
    
    //创建了滚动视图
    _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    _scrollView.contentSize = CGSizeMake(BGWidth, 909);
    _scrollView.backgroundColor = [UIColor whiteColor];
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.scrollEnabled = YES;
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
    //设置成NO表示当前控件响应后会传播到其他控件上，默认为YES。
    tapGestureRecognizer.cancelsTouchesInView = NO;
    //将触摸事件添加到view上
    [self.view addGestureRecognizer:tapGestureRecognizer];
    
    //第一部分的
    for (int i = 0; i < 3; i++) {
        
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(21, (i + 1) * 41, BGWidth - 42, 1)];
        v.backgroundColor = GWColor(239, 240, 241, 1);
        v.userInteractionEnabled = YES;
        [_scrollView addSubview:v];
        
    }
    
    UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 163, BGWidth, 10)];
    v1.backgroundColor = GWColor(239, 240, 241, 1);
    v1.userInteractionEnabled = YES;
    [_scrollView addSubview:v1];
    
    NSArray *arr = @[@"分类 :",@"货品名称 :",@"产品品牌 :",@"数量(吨) :"];
    
    //11
    UIButton *btn11 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, BGWidth, 41)];
    [_scrollView addSubview:btn11];
    btn11.tag = 10;
    [btn11 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *image11 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, (41 - 10) / 2, 10, 10)];
    image11.image = [UIImage imageNamed:@"更多信息"];
    [_scrollView addSubview:image11];
    
    UILabel *lab11 = [[UILabel alloc] init];
    lab11.text = arr[0];
    lab11.font = [UIFont systemFontOfSize:14];
    CGSize size11 = [lab11.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab11.font,NSFontAttributeName, nil]];
    lab11.frame = CGRectMake(21, (40 - size11.height) / 2, size11.width, size11.height);
    lab11.userInteractionEnabled = YES;
    [_scrollView addSubview:lab11];
    
    filed11 = [[UITextField alloc] initWithFrame:CGRectMake(lab11.right + 10, lab11.y, 190, lab11.height)];
    filed11.font = [UIFont systemFontOfSize:14];
    filed11.placeholder = @"请选择";
    NSInteger row=[picker2 selectedRowInComponent:0];
    NSString *value=[addTo objectAtIndex:row];
    filed11.text = value;
    filed11.userInteractionEnabled = NO;
    [_scrollView addSubview:filed11];
    
    //12
    UILabel *lab12 = [[UILabel alloc] init];
    lab12.text = arr[1];
    lab12.font = [UIFont systemFontOfSize:14];
    CGSize size12 = [lab12.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab12.font,NSFontAttributeName, nil]];
    lab12.frame = CGRectMake(21, (40 - size12.height) / 2 + 41, size12.width, size12.height);
    lab12.userInteractionEnabled = YES;
    [_scrollView addSubview:lab12];
    
    filed12 = [[UITextField alloc] initWithFrame:CGRectMake(lab12.right + 10, lab12.y, 190, lab12.height)];
    filed12.font = [UIFont systemFontOfSize:14];
    filed12.placeholder = @"请填写";
    filed12.userInteractionEnabled = YES;
    [_scrollView addSubview:filed12];
    
    //13
    UILabel *lab13 = [[UILabel alloc] init];
    lab13.text = arr[2];
    lab13.font = [UIFont systemFontOfSize:14];
    CGSize size13 = [lab13.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab13.font,NSFontAttributeName, nil]];
    lab13.frame = CGRectMake(21, (40 - size13.height) / 2 + 41 * 2, size13.width, size13.height);
    lab13.userInteractionEnabled = YES;
    [_scrollView addSubview:lab13];
    
    filed13 = [[UITextField alloc] initWithFrame:CGRectMake(lab13.right + 10, lab13.y, 190, lab13.height)];
    filed13.font = [UIFont systemFontOfSize:14];
    filed13.placeholder = @"请填写";
    filed13.userInteractionEnabled = YES;
    [_scrollView addSubview:filed13];
    
    //14
    UILabel *lab14 = [[UILabel alloc] init];
    lab14.text = arr[3];
    lab14.font = [UIFont systemFontOfSize:14];
    CGSize size14 = [lab14.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab14.font,NSFontAttributeName, nil]];
    lab14.frame = CGRectMake(21, (40 - size14.height) / 2 + 41 * 3, size14.width, size14.height);
    lab14.userInteractionEnabled = YES;
    [_scrollView addSubview:lab14];
    
    filed14 = [[UITextField alloc] initWithFrame:CGRectMake(lab14.right + 10, lab14.y, 190, lab14.height)];
    filed14.font = [UIFont systemFontOfSize:14];
    filed14.placeholder = @"请填写";
    filed14.userInteractionEnabled = YES;
    filed14.keyboardType = UIKeyboardTypeDecimalPad;
    [_scrollView addSubview:filed14];
    [filed14 addTarget:self
                action:@selector(valuechange)
      forControlEvents:UIControlEventEditingChanged];
    
    
    //第二步
    NSArray *arr2 = @[@"发布类型 :",@"单价(元) :",@"是否拆分出售 :",@"最小供应量(吨) :",@"阶梯价格(选填) :"];
    for (int i = 0; i <= 4; i++) {
        
        if (i != 4) {
            
            UIView *v = [[UIView alloc] initWithFrame:CGRectMake(21, v1.bottom + (i + 1) * 41, BGWidth - 42, 1)];
            v.backgroundColor = GWColor(239, 240, 241, 1);
            [_scrollView addSubview:v];
            
        }
        
        
    }
    
    //定向单的图 为了位移
    dingxiangdan = [[UIView alloc] initWithFrame:CGRectMake(0, 204 + v1.bottom, BGWidth, BGHight)];
    dingxiangdan.backgroundColor = [UIColor whiteColor];
    v2Y = dingxiangdan.y;
    [_scrollView addSubview:dingxiangdan];
    
    v2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, BGWidth, 10)];
    v2.backgroundColor = GWColor(239, 240, 241, 1);
    [dingxiangdan addSubview:v2];
    
    //21第二部分的第一部分
    UIButton *btn21 = [[UIButton alloc] initWithFrame:CGRectMake(0, v1.bottom, BGWidth, 41)];
    [_scrollView addSubview:btn21];
    btn21.tag = 11;
    [btn21 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *image21 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v1.bottom + (41 - 10) / 2, 10, 10)];
    image21.image = [UIImage imageNamed:@"更多信息"];
    [_scrollView addSubview:image21];
    
    UILabel *lab21 = [[UILabel alloc] init];
    lab21.text = arr2[0];
    lab21.font = [UIFont systemFontOfSize:14];
    CGSize size21 = [lab21.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab21.font,NSFontAttributeName, nil]];
    lab21.frame = CGRectMake(21, (40 - size21.height) / 2 + v1.bottom, size21.width, size21.height);
    lab21.userInteractionEnabled = YES;
    [_scrollView addSubview:lab21];
    
    filed21 = [[UITextField alloc] initWithFrame:CGRectMake(lab21.right + 10, lab21.y, 190, lab21.height)];
    filed21.font = [UIFont systemFontOfSize:14];
    filed21.text = @"商城";
    filed21.userInteractionEnabled = NO;
    [filed21 addTarget:self action:@selector(panduanfabuleixing) forControlEvents:UIControlEventEditingChanged];
    [_scrollView addSubview:filed21];
    
    //22
    lab22 = [[UILabel alloc] init];
    lab22.text = arr2[1];
    lab22.font = [UIFont systemFontOfSize:14];
    CGSize size22 = [lab22.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab22.font,NSFontAttributeName, nil]];
    lab22.frame = CGRectMake(21, (40 - size22.height) / 2 + v1.bottom + 41, size22.width, size22.height);
    [_scrollView addSubview:lab22];
    
    filed22 = [[UITextField alloc] initWithFrame:CGRectMake(lab22.right + 10, lab22.y, 190, lab22.height)];
    [filed22 addTarget:self action:@selector(texfiledchange:) forControlEvents:UIControlEventEditingDidEnd];
    filed22.font = [UIFont systemFontOfSize:14];
    filed22.placeholder = @"请填写";
    filed22.userInteractionEnabled = YES;
    filed22.textColor = [UIColor redColor];
    filed22.keyboardType = UIKeyboardTypeDecimalPad;
    [_scrollView addSubview:filed22];
    [filed22 addTarget:self action:@selector(valuechange) forControlEvents:UIControlEventEditingChanged];
    //221
    filed221 = [[UITextField alloc] initWithFrame:CGRectMake(lab22.right + 16, lab22.y, 190, lab22.height)];
    filed221.font = [UIFont systemFontOfSize:14];
    filed221.placeholder = @"请填写";
    filed221.userInteractionEnabled = YES;
    filed221.textColor = [UIColor redColor];
    filed221.hidden = YES;
    filed221.keyboardType = UIKeyboardTypeDecimalPad;
    [_scrollView addSubview:filed221];
    [filed221 addTarget:self action:@selector(valuechange) forControlEvents:UIControlEventEditingChanged];
    [filed221 addTarget:self action:@selector(texfiledchange:) forControlEvents:UIControlEventEditingDidEnd];
    
    //23
    btn23 = [[UIButton alloc] initWithFrame:CGRectMake(0, v1.bottom + 41 * 2, BGWidth, 41)];
    [_scrollView addSubview:btn23];
    btn23.tag = 12;
    [btn23 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    image23 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v1.bottom + 41 * 2 + (41 - 10) / 2, 10, 10)];
    image23.image = [UIImage imageNamed:@"更多信息"];
    [_scrollView addSubview:image23];
    
    
    lab23 = [[UILabel alloc] init];
    lab23.text = arr2[2];
    lab23.font = [UIFont systemFontOfSize:14];
    CGSize size23 = [lab23.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab23.font,NSFontAttributeName, nil]];
    lab23.frame = CGRectMake(21, (40 - size23.height) / 2 + v1.bottom + 41 * 2, size23.width, size23.height);
    lab23.userInteractionEnabled = YES;
    [_scrollView addSubview:lab23];
    
    filed23 = [[UITextField alloc] initWithFrame:CGRectMake(lab23.right + 10, lab23.y, 190, lab23.height)];
    filed23.font = [UIFont systemFontOfSize:14];
    filed23.placeholder = @"必选";
    filed23.text = @"否";
    isPortedStr = @"0";
    filed23.userInteractionEnabled = NO;
    filed23.keyboardType = UIKeyboardTypeDecimalPad;
    [_scrollView addSubview:filed23];
    
    //24
    lab24 = [[UILabel alloc] init];
    lab24.text = arr2[3];
    lab24.font = [UIFont systemFontOfSize:14];
    CGSize size24 = [lab24.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab24.font,NSFontAttributeName, nil]];
    lab24.frame = CGRectMake(21, (40 - size24.height) / 2 + v1.bottom + 41 * 3, size24.width, size24.height);
    lab24.userInteractionEnabled = YES;
    [_scrollView addSubview:lab24];
    
    filed24 = [[UITextField alloc] initWithFrame:CGRectMake(lab24.right + 10, lab24.y, 190, lab24.height)];
    filed24.font = [UIFont systemFontOfSize:14];
    filed24.placeholder = @"请填写";
    filed24.userInteractionEnabled = YES;
    filed24.keyboardType = UIKeyboardTypeDecimalPad;
    [_scrollView addSubview:filed24];
    //241
    filed241 = [[UITextField alloc] initWithFrame:CGRectMake(lab24.right + 16, lab24.y, 190, lab24.height)];
    filed241.hidden = YES;
    filed241.font = [UIFont systemFontOfSize:14];
    filed241.placeholder = @"请填写";
    filed241.userInteractionEnabled = YES;
    filed241.textColor = [UIColor redColor];
    filed241.keyboardType = UIKeyboardTypeDecimalPad;
    [_scrollView addSubview:filed241];
    
    //25
    btn25 = [[UIButton alloc] initWithFrame:CGRectMake(0, v1.bottom + 41 * 4, BGWidth, 41)];
    [_scrollView addSubview:btn25];
    btn25.tag = 13;
    [btn25 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    image25 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v1.bottom + 41 * 4 +(41 - 10) / 2, 10, 10)];
    image25.image = [UIImage imageNamed:@"更多信息"];
    [_scrollView addSubview:image25];
    
    lab25 = [[UILabel alloc] init];
    lab25.text = arr2[4];
    lab25.font = [UIFont systemFontOfSize:14];
    CGSize size25 = [lab25.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab25.font,NSFontAttributeName, nil]];
    lab25.frame = CGRectMake(21, (40 - size25.height) / 2 + v1.bottom + 41 * 4, size25.width, size25.height);
    lab25.userInteractionEnabled = YES;
    [_scrollView addSubview:lab25];
    
    filed25 = [[UITextField alloc] initWithFrame:CGRectMake(lab25.right + 10, lab25.y, 190, lab25.height)];
    filed25.font = [UIFont systemFontOfSize:14];
    filed25.placeholder = @"请填写";
    filed25.userInteractionEnabled = NO;
    filed25.keyboardType = UIKeyboardTypeDecimalPad;
    [_scrollView addSubview:filed25];
    
    //第三步
    NSArray *arr3 = @[@"支付方式 :",@"挂单方式 :",@"仓单图片 :"];
    
    //通过支付方式改变视图
    zhifuView = [[UIView alloc] initWithFrame:CGRectMake(0, v2.bottom + 41, BGWidth, 374)];
    zhifuView.backgroundColor = [UIColor whiteColor];
    
    zhifuViewY = zhifuView.y;
    
    for (int i = 0; i < 2; i++) {
        
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(21, v2.bottom + (i + 1) * 41 - 51, BGWidth - 42, 1)];
        v.backgroundColor = GWColor(239, 240, 241, 1);
        [zhifuView addSubview:v];
        
    }
    
    UIView *v3 = [[UIView alloc] initWithFrame:CGRectMake(0, 123 + v2.bottom - 51, BGWidth, 10)];
    v3.backgroundColor = GWColor(239, 240, 241, 1);
    [zhifuView addSubview:v3];
    
    //31
    btn31 = [[UIButton alloc] initWithFrame:CGRectMake(0, v2.bottom, BGWidth, 41)];
    [dingxiangdan addSubview:btn31];
    btn31.tag = 14;
    [btn31 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *image31 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v2.bottom +(41 - 10) / 2, 10, 10)];
    image31.image = [UIImage imageNamed:@"更多信息"];
    [dingxiangdan addSubview:image31];
    
    UILabel *lab31 = [[UILabel alloc] init];
    lab31.text = arr3[0];
    lab31.font = [UIFont systemFontOfSize:14];
    CGSize size31 = [lab31.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab31.font,NSFontAttributeName, nil]];
    lab31.frame = CGRectMake(21, (40 - size31.height) / 2 + v2.bottom, size31.width, size31.height);
    lab31.userInteractionEnabled = YES;
    [dingxiangdan addSubview:lab31];
    
    filed31 = [[UITextField alloc] initWithFrame:CGRectMake(lab31.right + 10, lab31.y, 70, lab31.height)];
    filed31.font = [UIFont systemFontOfSize:14];
    filed31.placeholder = @"请选择";
    filed31.userInteractionEnabled = NO;
    [dingxiangdan addSubview:filed31];
    
    //31位置上当为分期付款时
    lab311 = [[UILabel alloc] init];
    lab311.text = @"首期款：";
    lab311.font = [UIFont systemFontOfSize:14];
    CGSize size311 = [lab311.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab311.font,NSFontAttributeName, nil]];
    lab311.frame = CGRectMake(21, lab31.bottom + 18, size311.width, size311.height);
    [dingxiangdan addSubview:lab311];
    
    filed311 = [[UITextField alloc] initWithFrame:CGRectMake(lab311.right, lab311.y, 50, lab311.height)];
    filed311.placeholder = @"百分比";
    filed311.borderStyle = UITextBorderStyleNone;
    filed311.font = [UIFont systemFontOfSize:14];
    [dingxiangdan addSubview:filed311];
    
    UILabel *lab312 = [[UILabel alloc] init];
    lab312.text = @"中期款：";
    lab312.font = [UIFont systemFontOfSize:14];
    CGSize size312 = [lab312.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab312.font,NSFontAttributeName, nil]];
    lab312.frame = CGRectMake(filed311.right + 5, lab31.bottom + 18, size312.width, size312.height);
    [dingxiangdan addSubview:lab312];
    
    filed312 = [[UITextField alloc] initWithFrame:CGRectMake(lab312.right, lab312.y, 50, lab312.height)];
    filed312.font = [UIFont systemFontOfSize:14];
    filed312.borderStyle = UITextBorderStyleNone;
    filed312.placeholder = @"百分比";
    [dingxiangdan addSubview:filed312];
    
    UILabel *lab313 = [[UILabel alloc] init];
    lab313.text = @"尾款：";
    lab313.font = [UIFont systemFontOfSize:14];
    CGSize size313 = [lab313.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab313.font,NSFontAttributeName, nil]];
    lab313.frame = CGRectMake(filed312.right + 5, lab31.bottom + 18, size313.width, size313.height);
    [dingxiangdan addSubview:lab313];
    
    filed313 = [[UITextField alloc] initWithFrame:CGRectMake(lab313.right, lab313.y, 50, lab313.height)];
    filed313.font = [UIFont systemFontOfSize:14];
    filed313.placeholder = @"百分比";
    filed313.borderStyle = UITextBorderStyleNone;
    [dingxiangdan addSubview:filed313];
    
    //32
    btn32 = [[UIButton alloc] initWithFrame:CGRectMake(0, v2.bottom + 41 - 51, BGWidth, 41)];
    [zhifuView addSubview:btn32];
    btn32.tag = 15;
    [btn32 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    image32 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v2.bottom + 41 +(41 - 10) / 2 - 51, 10, 10)];
    image32.image = [UIImage imageNamed:@"更多信息"];
    [zhifuView addSubview:image32];
    
    lab32 = [[UILabel alloc] init];
    lab32.text = arr3[1];
    lab32.font = [UIFont systemFontOfSize:14];
    CGSize size32 = [lab32.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab32.font,NSFontAttributeName, nil]];
    lab32.frame = CGRectMake(21, (40 - size32.height) / 2 + v2.bottom + 41 - 51, size32.width, size32.height);
    lab32.userInteractionEnabled = YES;
    [zhifuView addSubview:lab32];
    
    filed32 = [[UITextField alloc] initWithFrame:CGRectMake(lab32.right + 10, lab32.y, 190, lab32.height)];
    filed32.font = [UIFont systemFontOfSize:14];
    filed32.placeholder = @"请选择";
    filed32.userInteractionEnabled = NO;
    [filed32 addTarget:self action:@selector(panduanguadanfangshi) forControlEvents:UIControlEventEditingChanged];
    [zhifuView addSubview:filed32];
    
    //33
    btn33 = [[UIButton alloc] initWithFrame:CGRectMake(0, v2.bottom + 41 * 2 - 51, BGWidth, 41)];
    [zhifuView addSubview:btn33];
    btn33.tag = 16;
    [btn33 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    image33 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v2.bottom + 41 * 2 +(41 - 10) / 2 - 51, 10, 10)];
    image33.image = [UIImage imageNamed:@"更多信息"];
    [zhifuView addSubview:image33];
    
    lab33 = [[UILabel alloc] init];
    lab33.text = arr3[2];
    lab33.font = [UIFont systemFontOfSize:14];
    CGSize size33 = [lab33.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab33.font,NSFontAttributeName, nil]];
    lab33.frame = CGRectMake(21, (40 - size33.height) / 2 + v2.bottom + 41 * 2 - 51, size33.width, size33.height);
    lab33.userInteractionEnabled = YES;
    [zhifuView addSubview:lab33];
    
    filed33 = [[UITextField alloc] initWithFrame:CGRectMake(lab33.right + 10, lab33.y, 190, lab33.height)];
    filed33.font = [UIFont systemFontOfSize:14];
    filed33.placeholder = @"请选择";
    filed33.userInteractionEnabled = NO;
    [zhifuView addSubview:filed33];
    
    //保证金 和 信誉值
    lab331 = [[UILabel alloc] init];
    lab331.text = @"当前可用金额:100";
    lab331.font = [UIFont systemFontOfSize:10];
    CGSize lab331size = [lab331.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab331.font,NSFontAttributeName, nil]];
    lab331.frame = CGRectMake(lab33.right + 10, lab33.y - 5, lab331size.width + 70, lab331size.height);
    lab331.hidden = YES;
    [zhifuView addSubview:lab331];
    
    lab332 = [[UILabel alloc] init];
    lab332.text = @"挂单需要冻结金额:100";
    lab332.font = [UIFont systemFontOfSize:10];
    NSMutableAttributedString *str332 = [[NSMutableAttributedString alloc] initWithString:lab332.text];
    [str332 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(9, 3)];
    CGSize lab332size = [lab332.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab332.font,NSFontAttributeName, nil]];
    lab332.frame = CGRectMake(lab33.right + 10, lab331.bottom + 2, lab332size.width +70, lab332size.height);
    lab332.attributedText = str332;
    lab332.hidden = YES;
    [zhifuView addSubview:lab332];
    
    //判断拆分的状态
    [self panduanChaifen];
    
    //第四步
    for (int i = 0; i < 5; i++) {
        
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(21, v3.bottom + (i + 1) * 41, BGWidth - 42, 1)];
        v.backgroundColor = GWColor(239, 240, 241, 1);
        [zhifuView addSubview:v];
        
    }
    NSArray *arr4 = @[@"定向用户(选填) :",@"所在地 :",@"交割方式(选填) :",@"开始日期(选填) :",@"结束日期(选填) :",@"填写备注 :"];
    
    //41
    UILabel *lab41 = [[UILabel alloc] init];
    lab41.text = arr4[0];
    lab41.font = [UIFont systemFontOfSize:14];
    CGSize size41 = [lab41.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab41.font,NSFontAttributeName, nil]];
    lab41.frame = CGRectMake(21, (40 - size41.height) / 2 + v3.bottom, size41.width, size41.height);
    lab41.userInteractionEnabled = YES;
    [zhifuView addSubview:lab41];
    
    filed41 = [[UITextField alloc] initWithFrame:CGRectMake(lab41.right + 10, lab41.y, 190, lab41.height)];
    filed41.font = [UIFont systemFontOfSize:14];
    filed41.placeholder = @"不可填";
    filed41.userInteractionEnabled = NO;
    [zhifuView addSubview:filed41];
    
    //42
    UIButton *btn42 = [[UIButton alloc] initWithFrame:CGRectMake(0, v3.bottom + 41, BGWidth, 41)];
    [zhifuView addSubview:btn42];
    btn42.tag = 17;
    [btn42 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *image42 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v3.bottom +(41 - 10) / 2 + 41, 10, 10)];
    image42.image = [UIImage imageNamed:@"更多信息"];
    [zhifuView addSubview:image42];
    
    UILabel *lab42 = [[UILabel alloc] init];
    lab42.text = arr4[1];
    lab42.font = [UIFont systemFontOfSize:14];
    CGSize size42 = [lab42.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab42.font,NSFontAttributeName, nil]];
    lab42.frame = CGRectMake(21, (40 - size42.height) / 2 + v3.bottom + 41, size42.width, size42.height);
    lab42.userInteractionEnabled = YES;
    [zhifuView addSubview:lab42];
    
    filed42 = [[UITextField alloc] initWithFrame:CGRectMake(lab42.right + 10, lab42.y, 190, lab42.height)];
    filed42.font = [UIFont systemFontOfSize:14];
    filed42.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"suozaidi"];
    filed42.placeholder = @"请选择";
    filed42.userInteractionEnabled = NO;
    [zhifuView addSubview:filed42];
    
    //43
    btn43 = [[UIButton alloc] initWithFrame:CGRectMake(0, v3.bottom + 41 * 2, BGWidth, 41)];
    [zhifuView addSubview:btn43];
    btn43.tag = 18;
    [btn43 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *image43 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v3.bottom +(41 - 10) / 2 + 41 * 2, 10, 10)];
    image43.image = [UIImage imageNamed:@"更多信息"];
    [zhifuView addSubview:image43];
    
    UILabel *lab43 = [[UILabel alloc] init];
    lab43.text = arr4[2];
    lab43.font = [UIFont systemFontOfSize:14];
    CGSize size43 = [lab43.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab43.font,NSFontAttributeName, nil]];
    lab43.frame = CGRectMake(21, (40 - size43.height) / 2 + v3.bottom + 41 * 2, size43.width, size43.height);
    lab43.userInteractionEnabled = YES;
    [zhifuView addSubview:lab43];
    
    filed43 = [[UITextField alloc] initWithFrame:CGRectMake(lab43.right + 10, lab43.y, 190, lab43.height)];
    filed43.font = [UIFont systemFontOfSize:14];
    filed43.placeholder = @"请选择";
    filed43.userInteractionEnabled = NO;
    [zhifuView addSubview:filed43];
    
    //44
    UIButton *btn44 = [[UIButton alloc] initWithFrame:CGRectMake(0, v3.bottom + 41 * 3, BGWidth, 41)];
    [zhifuView addSubview:btn44];
    btn44.tag = 19;
    [btn44 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *image44 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v3.bottom +(41 - 10) / 2 + 41 * 3, 10, 10)];
    image44.image = [UIImage imageNamed:@"更多信息"];
    [zhifuView addSubview:image44];
    
    UILabel *lab44 = [[UILabel alloc] init];
    lab44.text = arr4[3];
    lab44.font = [UIFont systemFontOfSize:14];
    CGSize size44 = [lab44.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab44.font,NSFontAttributeName, nil]];
    lab44.frame = CGRectMake(21, (40 - size44.height) / 2 + v3.bottom + 41 * 3, size44.width, size44.height);
    lab44.userInteractionEnabled = YES;
    [zhifuView addSubview:lab44];
    
    filed44 = [[UITextField alloc] initWithFrame:CGRectMake(lab44.right + 10, lab44.y, 190, lab44.height)];
    filed44.font = [UIFont systemFontOfSize:14];
    filed44.placeholder = @"请选择";
    filed44.userInteractionEnabled = NO;
    [zhifuView addSubview:filed44];
    
    //45
    UIButton *btn45 = [[UIButton alloc] initWithFrame:CGRectMake(0, v3.bottom + 41 * 4, BGWidth, 41)];
    [zhifuView addSubview:btn45];
    btn45.tag = 20;
    [btn45 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *image45 = [[UIImageView alloc] initWithFrame:CGRectMake(BGWidth - 21 - 10, v3.bottom +(41 - 10) / 2 + 41 * 4, 10, 10)];
    image45.image = [UIImage imageNamed:@"更多信息"];
    [zhifuView addSubview:image45];
    
    UILabel *lab45 = [[UILabel alloc] init];
    lab45.text = arr4[4];
    lab45.font = [UIFont systemFontOfSize:14];
    CGSize size45 = [lab45.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab45.font,NSFontAttributeName, nil]];
    lab45.frame = CGRectMake(21, (40 - size45.height) / 2 + v3.bottom + 41 * 4, size45.width, size45.height);
    lab45.userInteractionEnabled = YES;
    [zhifuView addSubview:lab45];
    
    filed45 = [[UITextField alloc] initWithFrame:CGRectMake(lab45.right + 10, lab45.y, 190, lab45.height)];
    filed45.font = [UIFont systemFontOfSize:14];
    filed45.placeholder = @"请选择";
    filed45.userInteractionEnabled = NO;
    [zhifuView addSubview:filed45];
    
    //46
    UILabel *lab46 = [[UILabel alloc] init];
    lab46.text = arr4[5];
    lab46.font = [UIFont systemFontOfSize:14];
    CGSize size46 = [lab46.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:lab46.font,NSFontAttributeName, nil]];
    lab46.frame = CGRectMake(21, (40 - size46.height) / 2 + v3.bottom + 41 * 5, size46.width, size46.height);
    lab46.userInteractionEnabled = YES;
    [zhifuView addSubview:lab46];
    
    filed46 = [[UITextView alloc] initWithFrame:CGRectMake(lab46.right + 10, (40 - size46.height) / 2 + v3.bottom + 41 * 5 - 7, BGWidth - 41 - lab46.width, 70)];
    filed46.font = [UIFont systemFontOfSize:14];
    filed46.attributedText = [[NSAttributedString alloc] initWithString:@"输入你的内容" attributes:@{UITextAttributeTextColor:[UIColor lightGrayColor],NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    filed46.userInteractionEnabled = YES;
    
    [zhifuView addSubview:filed46];
    
    [dingxiangdan addSubview:zhifuView];
    
}
- (void)click:(id)sender {
    
    UIButton *btn = sender;
    
    BGJieTiJiaGeController *a = [[BGJieTiJiaGeController alloc] init];
    BGCangDanController *cda = [[BGCangDanController alloc] init];
    
    switch (btn.tag) {
        case 17:
            [self xianshi];
            break;
        case 19:
            [self datexianshi];
            break;
        case 13:
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:a animated:YES];
            break;
        case 10:
            [self loadFenlei];
            [self btnClick];
            [self xianshi1];
            break;
        case 20:
            [self btnClick];
            [self xianshidatePicker];
            break;
        case 11:
            [self btnClick];
            picker2Index = 11;
            picker2Arr = [NSArray arrayWithArray:addTo];
            arrId = [NSArray arrayWithArray:addToid];
            [self xianshiPicker2];
            [picker2 reloadAllComponents];
            [picker2 reloadInputViews];
            filed21.text = addTo[0];
            addtoStr = addToid[0];
            break;
        case 12:
            [self btnClick];
            picker2Index = 12;
            picker2Arr = [NSArray arrayWithArray:isPorted];
            arrId = [NSArray arrayWithArray:isPortedid];
            [self xianshiPicker2];
            [picker2 reloadAllComponents];
            [picker2 reloadInputViews];
            filed23.text = isPorted[0];
            isPortedStr = isPortedid[0];
            [self panduanChaifen];
            break;
        case 14:
            [self btnClick];
            picker2Index = 14;
            picker2Arr = [NSArray arrayWithArray:payType];
            arrId = [NSArray arrayWithArray:payTypeid];
            [self xianshiPicker2];
            [picker2 reloadAllComponents];
            [picker2 reloadInputViews];
            filed31.text = payType[0];
            payTypeidStr = payTypeid[0];
            break;
        case 15:
            [self btnClick];
            picker2Index = 15;
            picker2Arr = [NSArray arrayWithArray:publishType];
            arrId = [NSArray arrayWithArray:publishTypeid];
            [self xianshiPicker2];
            [picker2 reloadAllComponents];
            [picker2 reloadInputViews];
            filed32.text = publishType[0];
            publishTypeidStr = publishTypeid[0];
            [self panduanguadanfangshi];
            break;
        case 18:
            [self btnClick];
            picker2Index = 18;
            picker2Arr = [NSArray arrayWithArray:deliveryType];
            arrId = [NSArray arrayWithArray:deliveryTypeid];
            [self xianshiPicker2];
            [picker2 reloadAllComponents];
            [picker2 reloadInputViews];
            filed43.text = deliveryType[0];
            deliveryTypeidStr = deliveryTypeid[0];
            break;
        case 16:
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:cda animated:YES];
            break;
        default:
            break;
    }
    
}
- (void)xianshidatePicker {
    
    dateIndex = 0;
    if (dateIndex == 0) {
        
        
        NSDate *date = [NSDate date];
        
        NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:3600*8];
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        [formatter setTimeZone:timeZone];
        [formatter setDateFormat:@"YYYY年MM月dd日 HH:mm"];
        //    [formatter setDateFormat:@"yyyy年MM月dd日(EEEE) HH:mm:ss"];
        _dateStr = [formatter stringFromDate:date];
        NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]];
        NSString *times = [timeSp substringToIndex:10];
        filed45.text = _dateStr;
        stopTime = times;
        
    }
    
    _dataPicker.hidden = NO;
    wancheng.hidden = NO;
    
}
- (void)xianshi1 {
    
    picker1.hidden = NO;
    wancheng.hidden = NO;
    
}
- (void)loadFenlei {
    
    [BGDateResult loadFenLeiWithLevel:@"level" key:@"no" success:^(NSObject *result) {
        
        BGFenLeiModel *model = (BGFenLeiModel *)result;
        
        fenleiThreeTitleArr = [NSMutableArray new];
        fenleiTwoTitleArr = [NSMutableArray new];
        fenleiOneTitleArr = [NSMutableArray new];
        idArr = [NSMutableArray new];
        
        //        NSMutableArray *one = [NSMutableArray array];
        
        for (BGTwoLevelDataModel *dataModel in model.res) {
            [fenleiOneTitleArr addObject:dataModel.title];
            
            
            
            NSMutableArray *two = [NSMutableArray new];
            NSMutableArray *twoTitle = [NSMutableArray array];
            NSMutableArray *t = [NSMutableArray new];
            NSMutableArray *tId = [NSMutableArray array];
            for (BGTwoLevelDataModel *twoModel in dataModel.children) {
                
                NSDictionary *dicTwo = @{
                                         @"catId":twoModel.catId,
                                         @"title":twoModel.title
                                         };
                [two addObject:dicTwo];
                [twoTitle addObject:twoModel.title];
                
                
                
                NSMutableArray *three = [[NSMutableArray alloc] init];
                NSMutableArray *threeTitle= [NSMutableArray array];
                NSMutableArray *threeId = [NSMutableArray array];
                for (BGTwoLevelDataModel *threeModel in twoModel.children) {
                    
                    NSDictionary *dicThree = @{
                                               @"catId":threeModel.catId,
                                               @"title":threeModel.title
                                               };
                    [threeTitle addObject:threeModel.title];
                    [three addObject:dicThree];
                    [threeId addObject:threeModel.catId];
                    
                    
                    
                }
                [t addObject:threeTitle];
                [tId addObject:threeId];
                
                
            }
            [fenleiTwoTitleArr addObject:twoTitle];
            [fenleiThreeTitleArr addObject:t];
            [idArr addObject:tId];
            
        }
        
        
        
        //        NSArray *array = @[fenleiOneTitleArr,fenleiTwoTitleArr,fenleiThreeTitleArr];
        //        LTOVEPickView *psss = [LTOVEPickView showPickViewWithHeigh:180 andDateArray:array];
        //        psss.x = 0;
        ////        psss.y = 300;
        //        [self.view addSubview:psss];
        [picker1 reloadInputViews];
        [picker1 reloadAllComponents];
        
    } failure:^(NSError *error) {
        
    }];
    
}
#pragma mark pickerDatasourece
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    
    if (pickerView.tag == 1) {
        
        return 3;
        
    }else if (pickerView.tag == 2) {
        
        return 3;
        
    }else if (pickerView.tag == 3){
        
        return 1;
        
    }else {
        return 0;
    }
    
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    
    
    if (pickerView.tag == 1) {
        
        if (component == 0) {
            
            //省
            return oneArr.count;
            
        }else if (component == 1) {
            
            //市
            NSInteger selectedProvinceIndex = [self.picker selectedRowInComponent:0];
            
            NSDictionary *dic = oneArr[selectedProvinceIndex];
            
            twoArr = dic[@"child"];
            
            NSMutableArray *title = [NSMutableArray array];
            twoAreaId = [NSMutableArray array];
            
            for (NSDictionary *dic in twoArr) {
                
                [title addObject:dic[@"name"]];
                [twoAreaId addObject:dic[@"id"]];
                
            }
            
            twoTitleArr = [NSMutableArray arrayWithArray:title];
            
            return twoArr.count;
            
        }else {
            
            //县
            NSInteger selectedProvinceIndex = [self.picker selectedRowInComponent:1];
            
            NSDictionary *dic = twoArr[selectedProvinceIndex];
            
            threeArr = dic[@"child"];
            
            NSMutableArray *title = [NSMutableArray array];
            threeAreaId = [[NSMutableArray alloc] init];
            
            for (NSDictionary *dic in threeArr) {
                
                [title addObject:dic[@"name"]];
                [threeAreaId addObject:dic[@"id"]];
                
            }
            
            threeTitleArr = [NSMutableArray arrayWithArray:title];
            
            str1 = oneTitleArr[0];
            areaIdStr1 = oneAreaId[0];
            
            str2 = twoTitleArr[0];
            areaIdStr2 = twoAreaId[0];
            
            str3 = threeTitleArr[0];
            areaIdStr3 = threeAreaId[0];
            
            return threeArr.count;
            
        }
        
        
    }else if (pickerView.tag == 2) {
        
        
        
        if (component == 0) {
            
            return fenleiOneTitleArr.count;
            
            
        }else if (component == 1) {
            
            NSInteger selectedProvinceIndex1 = [picker1 selectedRowInComponent:0];
            NSArray *a = [NSArray arrayWithArray:fenleiTwoTitleArr[selectedProvinceIndex1]];
            
            return a.count;
            
        }else {
            
            NSInteger selectedProvinceIndex1 = [picker1 selectedRowInComponent:0];
            NSInteger selectedProvinceIndex2= [picker1 selectedRowInComponent:1];
            
            NSArray *a = [NSArray arrayWithArray:fenleiThreeTitleArr[selectedProvinceIndex1][selectedProvinceIndex2]];
            
            return a.count;
        }
        
    }else if (pickerView.tag == 3) {
        
        return picker2Arr.count;
        
    }else {
        
        return 0;
        
    }
    
    
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    
    
    if (pickerView.tag == 1) {
        
        if (component == 0) {
            
            NSString *str = oneTitleArr[row];
            
            return str;
            
        }else if (component == 1) {
            
            
            
            NSString *str = twoTitleArr[row];
            
            return str;
            
        }else {
            
            NSString *str = threeTitleArr[row];
            
            return str;
            
        }
        
        
    }else if (pickerView.tag == 2) {
        
        
        
        if (component == 0) {
            
            NSString *str = fenleiOneTitleArr[row];
            
            return str;
            
        }else if (component == 1) {
            
            NSInteger selectedProvinceIndex11 =[picker1 selectedRowInComponent:0];
            NSArray *a = [NSArray arrayWithArray:fenleiTwoTitleArr[selectedProvinceIndex11]];
            
            NSString *str = a[row];
            
            return str;
            
        }else {
            
            NSInteger selectedProvinceIndex11 =[picker1 selectedRowInComponent:0];
            NSInteger selectedProvinceIndex22 = [picker1 selectedRowInComponent:1];
            
            NSArray *a = [NSArray arrayWithArray:fenleiThreeTitleArr[selectedProvinceIndex11][selectedProvinceIndex22]];
            
            NSString *str = a[row];
            
            return str;
            
        }
        
        
    }else if (pickerView.tag == 3) {
        
        return picker2Arr[row];
        
    } else {
        return nil;
    }
    
    
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        // Setup label properties - frame, font, colors etc
        //adjustsFontSizeToFitWidth property to YES
        pickerLabel.minimumFontSize = 8;
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setBackgroundColor:[UIColor clearColor]];
        [pickerLabel setFont:[UIFont boldSystemFontOfSize:18]];
    }
    // Fill the label text here
    pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    return pickerLabel;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    
    if (pickerView.tag == 1) {
        
        if (component == 0) {
            
            [self.picker reloadComponent:1];
            [self.picker reloadComponent:2];
            str1 = oneTitleArr[row];
            areaIdStr1 = oneAreaId[row];
            
        }else if (component == 1) {
            
            [self.picker reloadComponent:2];
            str2 = twoTitleArr[row];
            areaIdStr2 = twoAreaId[row];
            
        }else {
            
            str3 = threeTitleArr[row];
            areaIdStr3 = threeAreaId[row];
            
        }
        
        place = [NSString stringWithFormat:@"%@%@%@",str1,str2,str3,nil];
        filed42.text = place;
        
        [[NSUserDefaults standardUserDefaults] setObject:place forKey:@"suozaidi"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
    }else if (pickerView.tag == 2) {
        
        if (component == 0) {
            
            [picker1 reloadComponent:1];
            [picker1 reloadComponent:2];
            
            
        }else if (component == 1) {
            
            [picker1 reloadComponent:2];
            
            
        }else {
            
            
            
        }
        
        NSInteger selectedProvinceIndex11 =[picker1 selectedRowInComponent:0];
        NSInteger selectedProvinceIndex22 = [picker1 selectedRowInComponent:1];
        NSInteger selectedProvinceIndex33 = [picker1 selectedRowInComponent:2];
        
        NSArray *arr = [NSArray arrayWithArray:fenleiThreeTitleArr[selectedProvinceIndex11][selectedProvinceIndex22]];
        
        NSString *str = arr[selectedProvinceIndex33];
        self.Id = idArr[selectedProvinceIndex11][selectedProvinceIndex22][selectedProvinceIndex33];
        //        BGFuJiaController *a = [[BGFuJiaController alloc] init];
        //        a.typeId = self.Id;
        
        filed11.text = str;
        
    }else if (pickerView.tag == 3) {
        
        picker2Str = picker2Arr[row];
        pickerId = arrId[row];
        
        if (picker2Index == 11) {
            filed21.text = picker2Str;
            addtoStr = pickerId;
            
            [filed21 addTarget:self action:@selector(panduanfabuleixing) forControlEvents:UIControlEventValueChanged];
            [self panduanfabuleixing];
            [self panduanfabuleixing1];
        } else if (picker2Index == 12) {
            filed23.text = picker2Str;
            isPortedStr = pickerId;
            
            [self panduanChaifen];
        } else if (picker2Index == 14) {
            filed31.text = picker2Str;
            payTypeidStr = pickerId;
            
            [self panduanzhifufangshi];
        } else if (picker2Index == 15) {
            filed32.text = picker2Str;
            publishTypeidStr = pickerId;
            
            [self panduanguadanfangshi];
        } else {
            filed43.text = picker2Str;
            deliveryTypeidStr = pickerId;
            
        }
        
    }else {
        
    }
    
    
}
//判断支付的方式
- (void)panduanzhifufangshi {
    
    if ([filed31.text isEqualToString:@"分期"]) {
        
        zhifuView.y = zhifuViewY + 20 + lab311.height;
        
    } else if ([filed31.text isEqualToString:@"全款"]){
        
        filed311.text = @"100";
        filed312.text = @"0";
        filed313.text = @"0";
        payScaleStr = [NSString stringWithFormat:@"%d,%d,%d",100,0,0];
        
        zhifuView.y = zhifuViewY;
        
    } else {
        
        filed311.text = @"0";
        filed312.text = @"0";
        filed313.text = @"100";
        payScaleStr = [NSString stringWithFormat:@"%d,%d,%d",0,0,100];
        
        zhifuView.y = zhifuViewY;
    }
    
}
//判断是否可拆分
- (void)panduanChaifen {
    
    if ([filed23.text isEqualToString:@"是"]) {
        
        isPortedStr = @"1";
        
        filed24.userInteractionEnabled = YES;
        filed24.placeholder = @"请输入";
        
        btn25.userInteractionEnabled = YES;
        filed25.placeholder = @"请选择";
        
    }else {
        
        isPortedStr = @"0";
        
        _stepStr = @"";
        
        filed24.userInteractionEnabled = NO;
        filed24.placeholder = @"不可填";
        filed24.text = filed14.text;
        
        btn25.userInteractionEnabled = NO;
        filed25.placeholder = @"不可选";
        if ([filed21.text isEqualToString:@"商城"]) {
            
            yikoujia = @"0";
            
        }
        
    }
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    [filed12 resignFirstResponder];
    [filed13 resignFirstResponder];
    [filed14 resignFirstResponder];
    [filed22 resignFirstResponder];
    [filed24 resignFirstResponder];
    [filed23 resignFirstResponder];
    [filed25 resignFirstResponder];
    [filed41 resignFirstResponder];
    [filed46 resignFirstResponder];
    [filed311 resignFirstResponder];
    [filed312 resignFirstResponder];
    [filed313 resignFirstResponder];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)goodsDetail {
    
    NSLog(@"self.goodsId === %@",self.goodsId);
    
    [BGDateResult ownGoodsDetailWithGoodsId:self.goodsId success:^(NSObject *result) {
        
        [MBProgressHUD hideHUD];
        
        BGOwnGoodsDetailModel *model = (BGOwnGoodsDetailModel *)result;
        
        NSDictionary *dic = model.res;
        
//        BGOwnGoodsDetailValueModel *goods = model.res;
        
        NSLog(@"model === %@",dic[@"cat_name"]);
        
        //第一部分的
        filed11.text = dic[@"cat_name"];
        filed12.text = dic[@"title"];
        filed13.text = dic[@"product_code"];
        filed14.text = dic[@"number"];
        
        //第二部分的
        filed21.text = dic[@"add_to_str"];
        [self panduanfabuleixing];
        
        if ([filed21.text isEqualToString:@"商城"]) {
            filed22.text = dic[@"price"];
            filed23.text = dic[@"is_ported_str"];
            filed24.text = dic[@"least_number"];
            //            filed25.text = goods.total_price;
            //            filed25.userInteractionEnabled = YES;
        } else if ([filed21.text isEqualToString:@"拍卖"]) {
            NSLog(@"goods.total_price === %@",dic[@"total_price"]);
            filed221.text = dic[@"total_price"];
            filed23.text = dic[@"buy_margin"];
            filed241.text = dic[@"least_number"];
            filed25.text = dic[@"fixed_price"];
            
        } else {
            filed22.text = dic[@"price"];
            filed23.text = dic[@"is_ported_str"];
            filed24.text = dic[@"least_number"];
            filed25.text = dic[@"total_price"];
        }
        
        //        filed22.text = goods.price;
        //        filed23.text = goods.is_ported_str;
        //        filed24.text = goods.least_number;
        //        filed25.text = goods.total_price;
        
        //第三部分的
        filed31.text = dic[@"pay_type_str"];
        
        [self panduanzhifufangshi];
        
        if ([filed31.text isEqualToString:@"分期"]) {
            
            NSArray *arr = [dic[@"pay_scale"] componentsSeparatedByString:@","];
            
            filed311.text = arr[0];
            filed312.text = arr[1];
            filed313.text = arr[2];
            
        }
        //        else if ([filed31.text isEqualToString:@"分期"]) {
        //
        //        }else if ([filed31.text isEqualToString:@"货到付款"]) {
        //
        //        }
        filed32.text = dic[@"publish_type_str"];
        
        [self panduanguadanfangshi];
        
        //        if ([filed32.text isEqualToString:@"保证金挂单"]) {
        //
        ////            lab331.text = [NSString stringWithFormat:@"当前可用金额：%d",goods.cashStr];
        ////
        ////            lab332.text = [NSString stringWithFormat:@"挂单需要冻结金额：%d",goods.marginStr];
        //
        //        } else if ([filed32.text isEqualToString:@"仓单挂单"]) {
        //
        //        }else if ([filed32.text isEqualToString:@"信誉挂单"]) {
        //
        //        }
        //
        //第四部分的
        filed41.text = dic[@"to_user_phone"];
        filed42.text = dic[@"delivery_area"];
        filed43.text = dic[@"delivery_type_str"];
        filed44.text = dic[@"start_time_format"];
        filed45.text = dic[@"end_time_format"];
        filed46.text = dic[@"remark"];
        
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:@"请求失败!"];
//        [MBProgressHUD hideHUD];
    }];
    
}
- (void)viewWillDisappear:(BOOL)animated {
    self.type = @"";
    [self btnClick];
}
- (void)viewWillAppear:(BOOL)animated {
    
    NSLog(@"self.storePicStra === %@",self.storePicStra);
    
    [_scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    
    if ([self.type  isEqual: @"fujia"]) {
        
        [self panduanEdit];
        
    }
    else if ([self.type isEqual:@"WFB"]) {
        
        [MBProgressHUD showMessage:@"加载中..."];
        [self panduanEdit];
        [self goodsDetail];
        
    }
    else if ([self.type  isEqual: @"jieti"] || [self.type  isEqual: @"cangdan"]) {
        
        for (UIView *btn in _scrollView.subviews) {
            btn.userInteractionEnabled = YES;
        }
        filed11.userInteractionEnabled = NO;
        filed21.userInteractionEnabled = NO;
        filed23.userInteractionEnabled = NO;
        filed25.userInteractionEnabled = NO;
        filed31.userInteractionEnabled = NO;
        filed32.userInteractionEnabled = NO;
        filed42.userInteractionEnabled = NO;
        filed43.userInteractionEnabled = NO;
        filed44.userInteractionEnabled = NO;
        filed45.userInteractionEnabled = NO;
        
    } else {
        
        for (UIView *btn in _scrollView.subviews) {
            btn.userInteractionEnabled = YES;
        }
        filed11.userInteractionEnabled = NO;
        filed21.userInteractionEnabled = NO;
        filed23.userInteractionEnabled = NO;
        filed25.userInteractionEnabled = NO;
        filed31.userInteractionEnabled = NO;
        filed32.userInteractionEnabled = NO;
        filed42.userInteractionEnabled = NO;
        filed43.userInteractionEnabled = NO;
        filed44.userInteractionEnabled = NO;
        filed45.userInteractionEnabled = NO;
        [self clean];
        [self panduanguadanfangshi];
        
    }
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
